#ifndef LANGUAGE_H
#define LANGUAGE_H

#ifndef LANGUAGE_GLOBAL_H
#define LANGUAGE_GLOBAL_H

#include <QtCore/qglobal.h>
#include <QObject>
#include <QTranslator>
#include <QLocale>
#include <QMap>
#if defined(LANGUAGE_LIBRARY)
#  define LANGUAGESHARED_EXPORT Q_DECL_EXPORT
#else
#  define LANGUAGESHARED_EXPORT Q_DECL_IMPORT
#endif

#endif // LANGUAGE_GLOBAL_H

class LANGUAGESHARED_EXPORT LanguageLib : public QObject
{
    Q_OBJECT
public:
       enum Language {
           AnyLanguage = 0, //未设置
           ZH_CN, //中文
           EN_US //英文
       };
       Q_ENUM(Language)
public:
    LanguageLib(QObject *parent = nullptr);
    ~LanguageLib();
    ///
    /// \brief 获取类实例
    /// \return 实例
    ///
    static LanguageLib *getinstance();
    ///
    /// \brief 获取当前设置的语言
    /// \return
    ///
    Language getLanguage() const;
    void setLanguage(Language type);
    //用于一些组件属性绑定
    QLocale getLocale() const;

    QTranslator GetTranslatoHandle();

private:
    //QTranslator在Qt5.15才有language接口，低版本可以自己解析
    QString parseLanguage(const QString &qmpath);
signals:
    void languageChanged();

private:
    //当前语言设置
    Language lang{AnyLanguage};
    //加载翻译文件
    QTranslator trans;
    //语言枚举与language name的映射表
    QMap<Language,QString> langMap;
    //当前locale设置
    QLocale locale;

};

#endif // LANGUAGE_H
